package com.example.materialtest

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.animation.Animation
import android.widget.TextView
import androidx.fragment.app.Fragment


class FirstFragment : Fragment() {
    private val messageList1 = ArrayList<message>()
    private val messageList2 = ArrayList<message>()
    var listView1: ListViewSet? = null
    var listView2: ListViewSet? = null
    companion object{
        fun newInstance(): FirstFragment? {
            val fragment = FirstFragment()
            return fragment
        }
    }
    override fun onCreateView(
        inflater: LayoutInflater,
        container: ViewGroup?,
        savedInstanceState: Bundle?
    ): View? {
        val view=inflater.inflate(R.layout.firstpage, container, false)
        listView1 = view.findViewById<ListViewSet>(R.id.messagelistView1)
        listView2 = view.findViewById<ListViewSet>(R.id.messagelistView2)
        return view
    }
    private fun initMessage(){
        repeat(2){
            messageList1.add(message( "本周五闭馆通知",R.drawable.faburen,"发布人：管理员",R.drawable.riqi,"日期：2021-07-07 12:34:09","图书馆通知"))
            messageList1.add(message( "新生网上选课的通知",R.drawable.faburen,"发布人：教务处",R.drawable.riqi,"日期：2021-07-07 12:34:09","教务处通知"))
            messageList1.add(message( "食堂通知",R.drawable.faburen,"发布人：食堂负责人",R.drawable.riqi,"日期：2021-07-07 12:34:09","食堂通知"))
            messageList2.add(message( "新生网上选课的通知",R.drawable.faburen,"发布人：教务处",R.drawable.riqi,"日期：2021-07-07 12:34:09","教务处通知"))
            messageList2.add(message( "食堂通知",R.drawable.faburen,"发布人：食堂负责人",R.drawable.riqi,"日期：2021-07-07 12:34:09","食堂通知"))
            messageList2.add(message( "本周五闭馆通知",R.drawable.faburen,"发布人：管理员",R.drawable.riqi,"日期：2021-07-07 12:34:09","图书馆通知"))
        }
    }
    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        super.onViewCreated(view, savedInstanceState)
        val mess = view.findViewById<TextView>(R.id.mess)
        val news = view.findViewById<TextView>(R.id.news)
        mess.setOnClickListener {
            //mess.setTypeface(Typeface.DEFAULT,Typeface.BOLD)
            mess.getPaint().setFakeBoldText(true);
            news.getPaint().setFakeBoldText(false);
            //view.invalidate()
            listView1?.visibility=View.VISIBLE
            listView2?.visibility=View.INVISIBLE
        }
        news.setOnClickListener{
            //news.setTypeface(Typeface.DEFAULT,Typeface.BOLD)
            news.getPaint().setFakeBoldText(true);
            mess.getPaint().setFakeBoldText(false);
            //view.invalidate()
            listView1?.visibility=View.INVISIBLE
            listView2?.visibility=View.VISIBLE
        }
        initMessage()
        val adapter1 = MessageAdapter(activity!!,R.layout.messagelayout,messageList1)
        val adapter2 = MessageAdapter(activity!!,R.layout.messagelayout,messageList2)
        listView1!!.adapter=adapter1
        listView2!!.adapter=adapter2
    }
}
